XBtnMoney={["total"]=GetPlayerMoney("copper"),["session"]=0,["spent"]=0};
 
function XBarMoney_OnEvent(this,event)
-- ChatFrame1:AddMessage("XBar-Money : "..event);
	if (event=="LOADING_END") then
		this:RegisterEvent("PLAYER_MONEY");
		this:RegisterEvent("PLAYER_TRADE_MONEY");
	end	

	if (event=="PLAYER_MONEY" or event=="PLAYER_TRADE_MONEY") then 
		local temp=XBtnMoney["total"];
		local diff=0;
		XBtnMoney["total"]=GetPlayerMoney("copper");
		if (temp<XBtnMoney["total"]) then
			diff=math.ceil(XBtnMoney["total"]-temp);
			XBtnMoney["session"]=XBtnMoney["session"]+diff;
		elseif (temp>XBtnMoney["total"]) then
			diff=math.ceil(temp-XBtnMoney["total"]);
			XBtnMoney["spent"]=XBtnMoney["spent"]+diff;
		end
	end
-- Output
	local usrtxt={[1]=XBar["MoneyV1"],[2]=XBar["MoneyV2"]};
	local output="";
	for i=1,2 do
		usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[GOLD%]","|cffFFFFC7"..XBar_SetDecimals(GetPlayerMoney("copper")).."|r");
		usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[DIAS%]","|cffC7C7FF"..XBar_SetDecimals(GetPlayerMoney("account")).."|r");
		usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[RUBY%]","|cffFFC7C7"..XBar_SetDecimals(GetPlayerMoney("bonus")).."|r");
		usrtxt[i],_=XBar_StrReplace(usrtxt[i],"%[COIN%]","|cffC7C7C7"..XBar_SetDecimals(GetPlayerMoney("billdin")).."|r");
	end
	if (XBar["MoneyT1"]==true) then output=usrtxt[1]; end
	if (XBar["MoneyT2"]==true) then
		if (XBar["MoneyT1"]==true) then output=output.."\n"..usrtxt[2]; else output=usrtxt[2]; end
	end
	XBarMoney_F_Text:SetText(output);
-- EoL
end
